// pages/lawhall/index.js
const app = getApp()
const {
  messageset,
  messagetop,
  pay,
  messagehitching,
  edithitching
} = require('../../utils/api')
const {
  formatDate,
  formatYEAR
} = require('../../utils/util')
const dateTimePicker = require('../../utils/dateTimePicker.js');

const {
  fetch,
  newFetch,
  hasSensitiveWords,
  replaceAll
} = require('../../utils/fetch')
const {
  BASEURL
} = require('../../utils/baseurl')

import {
  Base
} from '../../utils/base.js';
var base = new Base();

Page({
  /**
   * 页面的初始数据
   */
  data: {
    type: '',
    type_id: 13,
    sub_type_id: 0,
    sub_type_info: [],

    pushName: '',
    pushPhone: '',

    logo_img: [],
    imgs: [],

    details: '',
    chufaDate: '',
    chufaTime: '',
    startAddress: [],
    endAddress: [],
    personcount_idx: 0,
    carnumber: '',

    sel_start_time: '',
    sel_top_idx: -1,
    topInfo: [],
    cur_mid: 0,
    // region: ['请选择地区', '', ''],
    // regidestination: ['请选择地区', '', ''],

    setout: '',
    purpose:'',

    picker_date: formatYEAR(new Date()),
    picker_time: '00:00',

    placetop_time: '00:00',
    personcount_data: [{
        id: 0,
        count: 1,
        name: '1人'
      },
      {
        id: 1,
        count: 2,
        name: '2人'
      },
      {
        id: 2,
        count: 3,
        name: '3人'
      },
      {
        id: 3,
        count: 4,
        name: '4人'
      }
    ],

    checked: false,
    checked1: true,
    startimedate: formatDate(new Date()),
    freindex: 0,
    topInfo: Array,
    timeArr: ['七天', '半个月', '一个月', '一季度', '半年', '一年'],
    currentDate: new Date().getTime(),
    show: false,
    // type_id:0,
    formatter(type, value) {
      if (type === 'year') {
        return `${value}年`
      } else if (type === 'month') {
        return `${value}月`
      }
      return value
    },

    merlogolist: [], //顺风车logo
    merlogoimgs: [],
    atlaslist: [], //顺风车图集
    atlasimgs: [],

    typeindex: null,
    editval: {}, //编辑
    editid: 0, //编辑id
    ispageEdit: true,
    formId: '',

    customItem: '全部',
    specificarea: null,
    systemInfo: '',
    isShare: false,
    isagent: 0,
    pubdisabled:false,
    savedisabled:false,

    show_tip: 0,
    tip: 'init',
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    if (wx.getStorageSync('specificarea')) {
      this.setData({
        specificarea: wx.getStorageSync('specificarea')
      })
    }

    if (wx.getStorageSync('userInfo')) {
      let userInfo = wx.getStorageSync('userInfo');
      if (userInfo.isagent == null) {
        this.setData({
          isagent: 0
        })
      } else {
        this.setData({
          isagent: userInfo.isagent
        })
      }
      if (this.data.isagent == 0) {
        this.setData({
          pushPhone: userInfo.mobile,
          pushName: userInfo.nickname
        })
      }
    }
    if (wx.getStorageSync('currentAddress')) {
      let addressval = wx.getStorageSync('currentAddress').address_component;
      let rgaddress = [addressval.city, addressval.province, addressval.district]
      this.setData({
        region: rgaddress
      })
    }

    fetch(`wx/message/${this.data.specificarea}/messageset`, 'POST').then(res => {
      this.setData({
        toptimes: res.toptimes
      })
    })

    fetch(`wx/message/${this.data.specificarea}/messagetop`, 'POST').then(res => {
      this.setData({
        topInfo: res
      })
    })

    var obj1 = dateTimePicker.dateTimePicker(this.data.startYear, this.data.endYear);
    this.setData({
      dateTime1: obj1.dateTime,
      dateTimeArray1: obj1.dateTimeArray
    });

    if (options.index) {
      this.setData({
        typeindex: options.index
      })
      var type_info = app.globalData.addtype[options.index];
      if (type_info) {
        var type_child_info = type_info['childList'];
        var sub_type_id = 0;
        if (type_child_info.length > 0) {
          sub_type_id = type_child_info[0]['id'];
        }
        this.setData({
          type: type_info.text,
          type_id: type_info.id,
          sub_type_info: type_child_info,
          sub_type_id: sub_type_id,
          merlogolist: [type_child_info[0].typeimg],
          merlogoimgs: [type_child_info[0].typeimg],
        })
      }
    }

    if (options.ediddata) {
      this.setData({
        editval: JSON.parse(options.ediddata),
        ispageEdit: false
      })
      var editdetails
      if(options.details) {
        editdetails = decodeURIComponent(options.details)
      }
      let {
        editval
      } = this.data;
      var imgsdata = (editval.imgs && editval.imgs.split(",")) || [];
      var content = editval.content && JSON.parse(editval.content);
      var staradtime = editval.startTime.substr(editval.startTime.length - 5)
      var chufapikertimt = content.chufaTime.substr(content.chufaTime.length - 5)

      // 第三层判断
      if (editval.typetwo && editval.typetwo) {
        this.setData({
          sub_type_id: editval.typetwo.id,
          sub_type_info: [editval.typetwo],
        })
      }

      this.setData({
        type: editval.typeone.title,
        type_id: editval.typeone.id,

        merlogolist: [editval.logo],
        merlogoimgs: [editval.logo],
        atlaslist: imgsdata,
        atlasimgs: imgsdata,
        remark: editval.remark,

        details: editdetails || '',
        pushName: editval.pushName,
        pushPhone: editval.pushPhone,

        carnumber: content.carnumber,
        // region: content.startAddress.split(","),
        // regidestination: content.endAddress.split(","),
        setout:content.startAddress,
        purpose:content.endAddress,
        personcount_idx: content.personcount - 1,

        placetop_time: staradtime,
        picker_time: chufapikertimt
        // startimedate:editval.startTime,
        // freindex:editval.day-1
        // startimedate: editval.startTime || this.data.startimedate,
        // freindex: editval.day == 0 ? 0 : editval.day - 1
      })
    }
    if (options.editid) {
      this.setData({
        editid: options.editid
      })
    }

    var that = this;
    wx.getSystemInfo({
      success: function (res) {
        if (res.system.indexOf('iOS') == 0) {
          that.setData({
            systemInfo: 'iOS'
          })
        } else {
          that.setData({
            systemInfo: 'Android'
          })
        }
      }
    })



  },
  bind_sub_type: function (e) {
    var id = e.currentTarget.dataset.id;
    var typeimg = e.currentTarget.dataset.typeimg;
    // base.getDataSet(e,'id')
    this.setData({
      sub_type_id: id,
      merlogolist: [typeimg],
      merlogoimgs: [typeimg],
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {},

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {},

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    let userInfo = wx.getStorageSync('userInfo');
    if (userInfo) {
      fetch(`wx/membershare/${this.data.specificarea}/addShare`, 'POST', {
        type: 1,
        typeId: 0,
        memberId: userInfo["id"]
      }).then(res => {
        this.setData({
          isShare: false,
          pubdisabled:false
        })
      })
    }
    // 设置菜单中的转发按钮触发转发事件时的转发内容
    var shareObj = {
      title: '顺风车', // 默认是小程序的名称(可以写slogan等)
      path: '/pages/index/index', // 默认是当前页面，必须是以‘/’开头的完整路径
      imageUrl: this.data.merlogolist[0],
    }
    return shareObj;
  },

  inputFn: function (data) {
    let {
      dataName,
      value
    } = data.detail
    this.setData({
      [dataName]: value
    })
  },
  showToast: function (title) {
    wx.showToast({
      title,
      icon: 'none',
      duration: 1000
    })
  },

  bind_xueli: function (e) {
    this.data.xueli_idx = e.detail.picker_idx;
  },
  bind_yuexin: function (e) {
    this.data.yuexin_idx = e.detail.picker_idx;
  },
  bind_workyear: function (e) {
    this.data.workyear_idx = e.detail.picker_idx;
  },

  // bind_cellcity:function(e){
  //     this.data.region = e.detail.region;
  // },
  // bind_remark: function (e) {
  //   this.data.remark_arr = e.detail.sel_items_arr;
  // },

  // bind_personcount:function(e) {
  //   this.data.personcount_idx = e.detail.picker_idx;
  // },
  // bind_shun_date:function(e){
  //   this.data.chufaDate = e.detail.picker_date;
  // },
  // bind_shun_time: function (e) {
  //   this.data.chufaTime = e.detail.picker_time;
  // },
  // bind_startAddress: function (e) {
  //   this.data.startAddress = e.detail.region;
  // },
  // bind_endAddress: function (e) {
  //   this.data.endAddress = e.detail.region;
  // },

  // bind_logo: function (e) {
  //   this.data.logo_img = e.detail.imageList;
  // },
  // bind_imgs: function (e) {
  //     this.data.imgs = e.detail.imagsetentlogs;
  // },

  // 出发地
  // bindRegionChange: function (e) {
  //   var val_arr = e.detail.value;
  //   if (val_arr[0] == '全部' && val_arr[1] == '全部' && val_arr[2] == '全部') {
  //     this.setData({
  //       region: ['请选择地区']
  //     })
  //     return;
  //   }
  //   this.setData({
  //     region: e.detail.value
  //   })
  // },

  goinputsetout: function (e) {
    this.setData({
      setout: e.detail.value
    })
  },

  // 目的地
  goinputpurpose: function (e) {
    this.setData({
      purpose: e.detail.value
    })
  },
  // binddestinationChange: function (e) {
  //   var val_arr = e.detail.value;
  //   if (val_arr[0] == '全部' && val_arr[1] == '全部' && val_arr[2] == '全部') {
  //     this.setData({
  //       regidestination: ['请选择地区']
  //     })
  //     return;
  //   }
  //   this.setData({
  //     regidestination: e.detail.value
  //   })
  // },

  // 出发日期
  bindDateChange: function (e) {
    this.setData({
      picker_date: e.detail.value
    })
  },
  // 出发时间
  bindTimeChange: function (e) {
    this.setData({
      picker_time: e.detail.value
    })
  },
  // 可乘人数
  bindtaskChange: function (e) {
    this.setData({
      personcount_idx: e.detail.value
    })
  },
  // 备注
  inputdetails: function (e) {
    this.setData({
      details: e.detail.value
    })
  },
  goinputCopy: function () {
    wx.setClipboardData({
      data: this.data.details,
      success: function (res) {
        // 添加下面的代码可以复写复制成功默认提示文本`内容已复制` 
        wx.showToast({
          title: '复制成功',
          duration: 3000
        })
        wx.getClipboardData({
          success: function (res) {}
        })
      }
    })
  },

  // 联系人
  inputpusName: function (e) {
    this.setData({
      pushName: e.detail.value
    })
  },
  // 联系电话
  inputpusPhone: function (e) {
    this.setData({
      pushPhone: e.detail.value
    })
  },
  // 车牌号码
  inputcarnumber: function (e) {
    this.setData({
      carnumber: e.detail.value
    })
  },

  // 置顶时间
  bindplacetopChange: function (e) {
    this.setData({
      placetop_time: e.detail.value
    })
  },

  // 上传logo图片
  upload(e) {
    const _this = this
    var imgtype = e.currentTarget.dataset.imgtype;
    var resupimg = []

    let {
      merlogolist,
      atlaslist,
      atlasimgs
    } = this.data;
    var imgcount = 1;
    if (imgtype == 'atlas') {
      imgcount = 9 - atlasimgs.length
    }
    wx.chooseImage({
      count: imgcount,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success: (res) => {
        var tempFilePaths = res.tempFilePaths;
        for (var i = 0; i < tempFilePaths.length; i++) {
          if (imgtype == 'logo') {
            merlogolist.push(tempFilePaths[i]);
            this.setData({
              merlogolist: merlogolist,
            })
            wx.uploadFile({
              url: `${BASEURL}wx/upload/image`,
              filePath: res.tempFilePaths[i],
              name: 'image',
              formData: {},
              success: (res) => {
                if (res.statusCode == 200) {
                  var resdata = JSON.parse(res.data);
                  this.setData({
                    // merlogoimgs:_this.data.merlogoimgs.concat(resdata.data.url),
                    merlogoimgs: [resdata.data.url],
                  })
                }
              },
              fail: function (res) {}
            })
          }
       
        }
           // 顺风车  九图
           if (imgtype == 'atlas') {
            _this.setData({
              tip: '已选图片,正在上传..',
              show_tip: 1,
            })
            res.tempFilePaths.forEach((item,index) => {
              wx.uploadFile({
                url: `${BASEURL}wx/upload/image`,
                filePath: item,
                name: 'image',
                formData: {
                  type: 'img'
                },
                success: (res) => {
                  var resdata = JSON.parse(res.data);
                  if (resdata.code == '200') {
                    resupimg[index] = resdata.data.url
                    this.setData({
                      atlasimgs: resupimg
                    })
                    _this.setData({
                          tip: '显示',
                          show_tip: 0
                        })
                  } else if (resdata.code == '404') {
                    wx.showToast({
                      title: res.data.msg,
                      icon: 'none'
                    })
                  }
                  },
                  fail: function (res) {
                    console.log(res, 'fail')
                  }
                })
            })

            
            // wx.uploadFile({
            //   url: `${BASEURL}wx/upload/image`,
            //   filePath: res.tempFilePaths[i],
            //   name: 'image',
            //   formData: {},
            //   success: (res) => {
            //     if (res.statusCode == 200) {
            //       var resdata = JSON.parse(res.data);
            //       this.setData({
            //         atlasimgs: _this.data.atlasimgs.concat(resdata.data.url),
            //       })
            //       _this.setData({
            //         tip: '显示',
            //         show_tip: 0
            //       })
            //     }
            //   },
            //   fail: function (res) {}
            // })
          }
      }
    })
  },
  previewImage(e) {
    let index = e.target.dataset.index
    let {
      merlogolist,
      atlaslist,
      atlasimgs
    } = this.data;
    var imgtype = e.currentTarget.dataset.imgtype;
    if (imgtype == 'logo') {
      wx.previewImage({
        current: merlogolist[index],
        urls: merlogolist
      })
    }
    if (imgtype == 'atlas') {
      wx.previewImage({
        current: atlasimgs[index],
        urls: atlasimgs
      })
    }


  },
  remove(e) {
    const _this = this
    let index = e.target.dataset.index
    let {
      merlogolist,
      atlaslist,
      merlogoimgs,
      atlasimgs
    } = this.data;
    var imgtype = e.currentTarget.dataset.imgtype;
    if (imgtype == 'logo') {
      wx.showModal({
        title: '提示',
        content: '您确定要删除本张图片吗？',
        success(res) {
          if (res.confirm) {
            merlogolist.splice(index, 1)
            merlogoimgs.splice(index, 1)
            _this.setData({
              merlogolist,
              merlogoimgs
            })
          } else if (res.cancel) {}
        }
      })
    }
    if (imgtype == 'atlas') {
      wx.showModal({
        title: '提示',
        content: '您确定要删除本张图片吗？',
        success(res) {
          if (res.confirm) {
            // atlaslist.splice(index, 1)
            atlasimgs.splice(index, 1)
            _this.setData({
              // atlaslist,
              atlasimgs
            })
          } else if (res.cancel) {}
        }
      })
    }
  },



  changeDateTime1(e) {
    let month = e.detail.value[1] + 1;
    let dtime = e.detail.value[2] + 1;
    let atime = '20' + e.detail.value[0] + '-' + month + '-' + dtime + ' ' + e.detail.value[3] + ':' + e.detail.value[4];
    this.setData({
      startimedate: atime
    })
  },
  changeDateTimeColumn1(e) {
    var arr = this.data.dateTime1,
      dateArr = this.data.dateTimeArray1;
    arr[e.detail.column] = e.detail.value;
    dateArr[2] = dateTimePicker.getMonthDay(dateArr[0][arr[0]], dateArr[1][arr[1]]);
    this.setData({
      dateTimeArray1: dateArr,
      dateTime1: arr
    });
  },



  // 是否置顶
  onChange(event) {
    if (this.data.type_id == 3 || this.data.type_id == '3') {
      wx.showToast({
        title: '商业信息发布必须置顶',
        icon: 'none',
        duration: 2000
      })
      return false;
    }
    this.setData({
      checked: event.detail
    })
  },
  onChange1(event) {
    this.setData({
      checked1: event.detail
    })
  },
  bindPickerChange: function (e) {
    this.setData({
      freindex: e.detail.value
    })
  },
  onInput(event) {
    var d = new Date(event.detail);
    d = formatDate(d);
    this.setData({
      currentDate: event.detail,
      startimedate: d
    })
  },
  togglePicker() {
    this.setData({
      show: !this.data.show,
    })
  },

  jumpToAgreement() {
    wx.navigateTo({
      url: '/pages/login/agreement'
    })
  },



  // 置顶
  publishFN: function (e) {
    this.setData({
      formId: e.detail.formId
    })

    if (this.data.checked == false) {
      this.data.sel_top_idx = -1;
    } else {
      // this.data.sel_top_idx = e.detail.sel_top;
      this.data.sel_top_idx = 0;
    }

    let data = this.data
    // if (data.region.indexOf('请选择地区') == 0) {
    //   this.showToast('请选择出发地');
    //   return;
    // }
    // if (data.regidestination.indexOf('请选择地区') == 0) {
    //   this.showToast('请选择目的地');
    //   return;
    // }

    if (!this.data.setout) {
      this.showToast('请选择出发地');
      return;
    }
    if (!this.data.purpose) {
      this.showToast('请选择目的地');
      return;
    }

    
    // chufaDate  chufaTime
    if (data.picker_date == '') {
      this.showToast('请选择出发日期');
      return;
    }
    if (data.picker_time == '') {
      this.showToast('请选择出发时间');
      return;
    }

    var newdetails = hasSensitiveWords(this.data.details)
    if (newdetails) {
      wx.showToast({
        title: '备注内容包含敏感词，已经自动处理为*，请重新编辑',
        icon: 'none',
        duration: 1500
      })
      this.setData({
        details: replaceAll(this.data.details, newdetails),
      });
      return;
    }

    if (this.data.details && this.data.details.indexOf('*') == 0) {
      this.showToast('请填写正确的备注内容');
      return;
    }

    // if (data.merlogolist.length<1) {
    //   this.showToast('请选择顺风车logo');
    //   return;
    // }
    //  if (data.atlaslist.length<1) {
    //   this.showToast('请上传图片');
    //   return;
    // }

    // if (!data.pushName) {
    //     this.showToast('请填写联系人');
    //     return;
    // }
    // if (!data.pushPhone) {
    //     this.showToast('请填写联系电话');
    //     return;
    // }
    // if (this.data.sub_type_id==28){
    //   if (!data.carnumber) {
    //     this.showToast('请填写车牌号');
    //     return;
    //   }
    // }
    let userInfo = wx.getStorageSync('userInfo');
    wx.showLoading({
      title: '发布中',
    })
    this.setData({
      pubdisabled:true
     })


    var re_param = {
      "area": this.data.specificarea,
      "memberId": userInfo["id"],
      "messageType1": data.type_id,
      "messageType2": data.sub_type_id,

      "logo": data.merlogoimgs.join(","),
      "imgs": data.atlasimgs || data.atlasimgs.join(","),

      "pushName": data.pushName,
      "pushPhone": data.pushPhone,

      "details": data.details && data.details.split('\n').join('&nbsp;'),
      "carnumber": data.carnumber,
      // 'startAddress': data.region.join(","),
      // 'endAddress': data.regidestination.join(","),
      'startAddress': data.setout,
      'endAddress': data.purpose,

      'personcount': data['personcount_data'][data.personcount_idx].count,

      "istop": 0,
      "startTime": '',
      "day": 0,
      "deadline": 0,
      "fee": 0
    };

    if (this.data.picker_date != '') {
      re_param["chufaTime"] = this.data.picker_date + ' ' + this.data.picker_time;
    }

    //选择置顶
    if (this.data.sel_top_idx >= 0) {
      var sel_top_info = this.data.topInfo[this.data.freindex];
      re_param["istop"] = 1;
      re_param["startTime"] = this.data.startimedate;
      re_param["day"] = sel_top_info['day'];
      re_param["deadline"] = this.data.toptimes;
      re_param["fee"] = sel_top_info['curmoney'];
    }

    var jump_url = '/pages/showmsg/index'; //'/pages/indexDetails/index?id=';
    this.data.cbj_url = jump_url;

    var that = this;

    if (this.data.typeindex) {
      newFetch(`wx/message/${this.data.specificarea}/che/fabu`, 'POST', re_param).then((res) => {
        if (res.data) {
          that.data.cur_mid = res.data.id;
          if (res.data.istop > 0) {
            wx.hideLoading()
            if (that.data.systemInfo == 'iOS') {
              wx.showToast({
                title: 'iOS不支持虚拟支付',
                icon: 'none',
                duration: 1500
              })
              return;
            }
            that.pay(res.data.fee, res.data.id, res.data.orderId);
          }
          if (res.data.istop == 0) {
            wx.hideLoading()
            that.endjump();
          }
          // if (res.data.fee==0){

          // } 
          if (res.data.limit == 0) {
            wx.hideLoading()
            this.setData({
              isShare: true
            })
          }
          // if(res.data.limit==1) {
          //   wx.hideLoading()
          //   wx.showToast({
          //     title: '您的免费发布次数已用完',
          //     icon:'none',
          //     duration:1500
          //   })
          //   return;
          // }
        }
      })
    }
    //  判断是否是编辑页面
    if (this.data.editval) {
      if (this.data.editid) {
        re_param['id'] = this.data.editid
        re_param['adStartTime'] = this.data.placetop_time
        re_param['details'] = data.details,
        this.setData({
          savedisabled:true
        })

        delete(re_param['remark'])

        if (this.data.checked) {
          wx.hideLoading()
          if (that.data.systemInfo == 'iOS') {
            wx.showToast({
              title: 'iOS不支持虚拟支付',
              icon: 'none',
              duration: 1500
            })
            return;
          }
          that.payRenew(this.data.editid, re_param)
        }  else {
          newFetch(`wx/message/${this.data.specificarea}/che/edit`, 'POST', re_param).then(res=>{
            if(res) {
                wx.hideLoading()
                that.endjump();
            }
          })
        }
      }
    }
  },
  pay: function (fee, typeId, orderId) {
    var that = this;
    let userInfo = wx.getStorageSync('userInfo');
    //return false
    let obg = {
      area: this.data.specificarea,
      openId: userInfo['openid'],
      memberId: userInfo['id'],
      // money: '0.01',
      money: this.data.topInfo[this.data.freindex]['curmoney'],
      orderdesc: '小微服务',
      orderId: orderId,
      type: 1,
      typeId: typeId,
      formId: that.data.formId
    }
    fetch(`wx/pay/${this.data.specificarea}/pay`, 'POST', obg).then(info => {
      wx.requestPayment({
        timeStamp: info.timeStamp,
        nonceStr: info.nonceStr,
        package: `prepay_id=${info.prepayId}`,
        signType: 'MD5',
        paySign: info.paySign,
        success: function (res) {
          wx.showToast({
            title: '付款成功',
            icon: 'success',
            duration: 2000
          })
          that.endjump();
        },
        fail: function (res) {
          that.setData({
            pubdisabled:false
          })
          wx.showToast({
            title: '取消付款成功',
            icon: 'success',
            duration: 2000
          })
        }
      })
    })
  },



  payRenew: function (typeId, re_param) {
    var that = this;
    let userInfo = wx.getStorageSync('userInfo');
    let obg = {
      area: this.data.specificarea,
      openId: userInfo['openid'],
      memberId: userInfo['id'],
      // money: '0.01',
      money: this.data.topInfo[this.data.freindex]['curmoney'],
      orderdesc: '小微服务',
      // orderId: orderId,
      type: 1,
      typeId: typeId,
      formId: that.data.formId
      // type就是那个消息1，商户2 广告3 typeid就是对应的id
    }
    fetch(`wx/pay/${this.data.specificarea}/payRenew`, 'POST', obg).then(info => {
      wx.requestPayment({
        timeStamp: info.timeStamp,
        nonceStr: info.nonceStr,
        package: `prepay_id=${info.prepayId}`,
        signType: 'MD5',
        paySign: info.paySign,
        success: function (res) {
          wx.showToast({
            title: '付款成功',
            icon: 'success',
            duration: 2000
          })
          that.saveEdit(info, re_param)
        },
        fail: function (res) {
          that.setData({
            savedisabled: false
          })
          wx.showToast({
            title: '取消付款成功',
            icon: 'success',
            duration: 2000
          })
        }
      })
    })
  },

  saveEdit:function (info, re_param) {
    var that = this;
    if (info.orderCode) {
      newFetch(`wx/pay/${this.data.specificarea}/checkOrderPayStatus`, 'POST', {
        orderId: info.orderCode
      }).then(res => {
        if (res.data.payStatus == 1) {
          re_param['payStatus'] = res.data.payStatus
          re_param['orderCode'] = res.data.orderCode
          newFetch(`wx/message/${this.data.specificarea}/che/edit`, 'POST', re_param).then(res=>{
            if(res) {
                wx.hideLoading()
                that.endjump();
            }
          })
        }
      })
    }
  },

  shareClose() {
    this.setData({
      isShare: false,
      pubdisabled:false
    })
  },

  endjump: function () {
    var that = this;
    setTimeout(() => {
      wx.redirectTo({
        url: that.data.cbj_url + "?id=" + 'indexid',
      })
    }, 3000)
  },

})